// Pages/sellSend/sellSend.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeData: [{ 'index': '1', 'typeName': '数码' }, { 'index': '2', 'typeName': '办公' }, { 'index': '3', 'typeName': '男装' }, { 'index': '4', 'typeName': '女装' }, { 'index': '5', 'typeName': '美妆' }, { 'index': '6', 'typeName': '鞋子' }, { 'index': '7', 'typeName': '箱包' }, { 'index': '8', 'typeName': '书籍' }, { 'index': '9', 'typeName': '其他' },],
    images: ["../../images/addimg.png"],
    index:10,

    thingName:'',
    describe:'',
    price:'',
    exchangeable:1,
    typeId:9,/**默认为其他 */
    pt:''
  },
  
  setThingsName:function(e){/**商品名称 */
      var that=this;
      that.setData({
        thingName:e.detail.value
      })
  },
  setPrice:function(e){/**销售价格 */
    var that = this;
    that.setData({
      price: e.detail.value
    })

  },
  setdescribe:function(e){
    var that =this;
    that.setData({
      describe:e.detail.value
    })
  },
  setchangeable:function(e){/*能否物物交换的标志 */

    var that =this;
    that.setData({
      exchangeable:e.detail.value
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  ss:function(e){/**设置商品分类 */
  console.log(e.detail.value)
    this.setData({
      index: e.detail.value,

    })
  },
  chooseimg:function(){
    var that=this;
    wx.chooseImage({
      count:1,
      success: function(res) {
          that.setData({
            images:res.tempFilePaths,
            pt:res.tempFilePaths[0]
          })

      },
    })
  },
  uploadAll:function(){
    var token=wx.getStorageSync('token')
    
    var that=this
    // console.log(that.data.index + 1)
      wx.uploadFile({
        url: 'http://47.103.21.65:5645/sell/postSale',
        filePath: that.data.pt,
        name: 'file1',
        header:{
          'token':token,

          'content-type': 'multipart/form-data'
        },
        formData:{
          thingName:that.data.thingName,
          describe:that.data.describe,
          price:that.data.price,
          exchangeable:that.data.exchangeable,
          newOld:1,
          typeId: (parseInt(that.data.index)+1)+"",
          exchangeable: that.data.exchangeable
        },
        success:function(res){
            console.log(res)
            wx.showToast({
              title: '发布成功',
              icon:'success'
            })

          setTimeout(function () {
            wx.navigateBack({
              delta: 1
            })
          }, 1000);
         
        },
        fail:function(res){

        }

      })
  }
})